<%-- 
    Document   : movieList
    Created on : May 1, 2013, 5:39:55 PM
    Author     : DevSteve
--%>

<%@page import="java.util.List"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.FileNotFoundException"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="db.DB"%>
<%@page import="db.MovieObj"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
        <title>Dataflix</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <meta http-equiv="content-language" content="en" />
        <meta name="description" content="" />
        <meta name="language" content="en" />
        <link type="text/css" rel="stylesheet" href="../css/style.css"/>
        <link type="text/css" rel="stylesheet" href="../css/style.css"/>
        <link type-="text/css" rel="stylesheet" href="../css/jquery-ui-1.9.2.custom.min.css"/>
        <link type-="text/css" rel="stylesheet" href="../css/timeline.css"/>
        <link type-="text/css" rel="stylesheet" href="../css/bootstrap.min.css"/>
        <style type="text/css">
            body {
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
        <script src="../js/jquery-1.9.1.min.js"></script>
        <script src="../js/jquery-ui-1.9.2.custom.min.js"></script>
        <script src="../js/bootstrap.min.js"></script>
        <script>
            
        </script>
        
    <head>
    <body>
                <table id="head">
                    <tr>
                        <td>
                            <a href="manager.jsp"><img style="margin-left:10%;" src="../images/logoadmin.png"/></a>
                        </td>

                        <td>
                            <table id="loginbox">
                                <tr>
                                    <td width="40%">
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <div class="bottom"></div>
                <div class="container-fluid">
            <h3>
                Movie List
                <INPUT Type="BUTTON"  class="btn" value="Add New" onclick="window.location.href = 'createMovie.jsp';" />
            </h3>
            <table class=" table">
            
                <% 

                java.sql.Connection con;
                java.sql.Statement s;
                java.sql.ResultSet rs;
                java.sql.PreparedStatement pst;

                con=null;
                s=null;
                pst=null;
                rs=null;

                DB data=new DB();
                
                
                String sql = "SELECT * FROM Movie";
                try{
                    con = data.getConnection();
                    s = con.createStatement();
                    rs = s.executeQuery(sql);
                %>
                <thead>
                <tr>
                <th  width="80px;">Id</th>
                <th  width="250px;">Name</th>
                <th  width="120px;">Type</th>
                <th  width="80px;">Rating</th>
                <th   width="120px;">District Fee</th>
                <th  width="80px;">Copies</th>
                <th  width="400px;">Description</th>
                <th>Edit</th>
                <th>Delete</th>
                </tr>
                </thead>
                
                <tbody id ="gridBody"> 
                <%
                while( rs.next() ){
                %><tr>
                <td ><%= rs.getString("Id") %></td>
                <td ><%= rs.getString("Name") %></td>
                <td ><%=rs.getString(3).toString()%></td>
                <td ><%=rs.getString(4).toString()%></td>
                <td ><%=rs.getString(5).toString()%></td>
                <td ><%=rs.getString(6).toString()%></td>
                <td >
                    <% String genre = rs.getString(3).toString(); %>
                    <% String id = rs.getString("Id"); %>
                    <%
                        String path=application.getRealPath("/");
                        File f=new File(path+"images/movies/"+ genre +"/movie"+ id +"Desc.txt");
                        FileInputStream fis=new FileInputStream(f);
                        InputStreamReader inStream = new InputStreamReader(fis);
			BufferedReader buff = new BufferedReader(inStream);
			
                        path=buff.readLine();
                        if(path.length()>100){
                            path = path.substring(0, 100);
                            path += "...";
                        }
                        out.print(path);
                    %>
                </td>
                <td style=" vertical-align: bottom;"><input type="button" class="btn" value="Edit" onclick="window.location.href = 'editMovie.jsp?id='+'<%=id%>';" /></td>
                <td style=" vertical-align: bottom;"><INPUT Type="BUTTON" class="btn" value="Delete" onclick="window.location.href = 'deleteMovie.jsp?id='+'<%=id%>';" /></td>
                </tr>
                <%
                }
                %>

                <%

                }
                catch(Exception e){e.printStackTrace();}
                finally{
                if(rs!=null) rs.close();
                if(s!=null) s.close();
                if(con!=null) con.close();
                }

                %>
                </tbody>
          </table>
        </div>
    <body>
</html>



